<?php

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars
define("PRIMARY_KEY","nobkt");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_dn_oth.php";
$FileTemplate  = "ais_transaction_dn_oth_list.html";
$TableName     = "ais_memorial";
$SubHeaderTitle= "Transaction Account Receivable - Debit Note";
$PageSize      = 10 ;
$HTMLGridList  = "DNGrid";

//************ FORM ACTION **************
    if (GetParam("Action","")=="Delete") {
        DeleteRecord ("txtCheck",$PageSize);
    }

//Initiate Database Table For Search;
$FCode = GetParam("dnSearch","");
//$FSkada = GetParam("skadaSearch","");
//$FDept = GetParam("deptSearch","");

//******* DATABASE FORM QUERY ***********


$SQL = "SELECT * FROM `$TableName` ";
$SQLCount = "SELECT count(*) FROM `$TableName` ";
$WHERE  = "ktrasl='".GetOfficeID()."' AND ".QueryLedger();

//Retrieve Parameter from search
if ($FCode) {
    $CustomWhere = " nobkt like '".$FCode."%'";
    if (strlen($WHERE)) $WHERE .= " AND ".$CustomWhere;
    else $WHERE = $CustomWhere;
}

if (strlen($WHERE)) $WHERE .= " AND urut=999 AND nobkt like 'ND%' AND flag_dn='OTH' AND nk_cancel_status = '' ";

if (strlen($WHERE)) {
    $SQL = $SQL."WHERE ".$WHERE;
    $SQLCount = $SQLCount."WHERE ".$WHERE;
} else $SQL = $SQL;

$SQL .= " ORDER BY tglbkt DESC, nobkt DESC";
//print $SQL;


/*
$SQL = "SELECT * FROM `$TableName` ";

if ($FCode) 
	if (strlen($WHERE)) $WHERE .= " AND nobkt like '".$FCode."%' ";
	else $WHERE .= " nobkt like '".$FCode."%' ";

if ($FJO) 
	if (strlen($WHERE)) $WHERE .= " AND jo_code like '%".$FJO."%' ";
	else $WHERE .= " bjo_code like '%".$FJO."%' ";
	
if ($FCust) 
	if (strlen($WHERE)) $WHERE .= " AND cust_name like '%".$FCust."%' ";
	else $WHERE .= " cust_name like '%".$FCust."%' ";	

if (strlen($WHERE))	$WHERE = " WHERE ktrasl='".GetOfficeID()."' AND ".QueryLedger()." AND urut=999 AND nobkt like 'ND%' AND flag_dn='OTH' AND nk_cancel_status = '' AND ".$WHERE;
	else $WHERE = " WHERE ktrasl='".GetOfficeID()."' AND ".QueryLedger()." AND urut=999 AND nobkt like 'ND%' AND flag_dn='OTH' AND nk_cancel_status = '' ";

$SQL = $SQL.$WHERE." ORDER BY tglbkt DESC, nobkt DESC ";
*/



//Select Customer
//$SQLDept = "SELECT * FROM tbldept";

//******* SHOW FORM CONTENT *********
$PageNum = 1;
$RecCnt = $DBConnection->dbc->get_var($SQLCount) ;

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);

$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
//$TBS->MergeBlock("deptblk",$DBMysql,$SQLDept);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ;
$TBS->Show();

function DeleteRecord ($sequence_name,$PageSize) {
    global $DBConnection,$FileName,$TableName;
    for ($x=1;$x<=$PageSize;$x++) {
        if (GetParam($sequence_name.$x,"")) {
            $DBConnection->Delete("$TableName",$sequence_name.$x);
        }
    }
    header("Location: $FileName");
    exit;

}

?>
